package com.zhaodui.dhcar.controller;
import com.zhaodui.dhcar.entity.FxjDhCarInfoEntity;
import com.zhaodui.dhcar.entity.FxjDhCarWzdetailEntity;
import com.zhaodui.dhcar.entity.FxjDhImpEntity;
import com.zhaodui.dhcar.service.FxjDhImpServiceI;

import java.io.*;
import java.util.*;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zhaodui.dhfk.entity.FxjDhfkLogEntity;
import com.zhaodui.jdwx.jdwxController;
import com.zhaodui.order.entity.FxjOrderAttaEntity;
import com.zhaodui.order.entity.FxjOrderMainEntity;
import com.zhaodui.restapi.entity.FileMeta;
import com.zhaodui.restapi.entity.fxj360wz;
import com.zhaodui.restapi.entity.jdwxerrres;
import io.swagger.models.auth.In;
import org.jeecgframework.core.util.*;
import org.jeecgframework.web.system.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.ui.ModelMap;
import org.springframework.util.FileCopyUtils;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import org.jeecgframework.core.common.controller.BaseController;
import org.jeecgframework.core.common.exception.BusinessException;
import org.jeecgframework.core.common.hibernate.qbc.CriteriaQuery;
import org.jeecgframework.core.common.model.json.AjaxJson;
import org.jeecgframework.core.common.model.json.DataGrid;
import org.jeecgframework.core.constant.Globals;
import org.jeecgframework.tag.core.easyui.TagUtil;
import org.jeecgframework.web.system.service.SystemService;

import org.jeecgframework.poi.excel.ExcelExportUtil;
import org.jeecgframework.poi.excel.ExcelImportUtil;
import org.jeecgframework.poi.excel.entity.ExportParams;
import org.jeecgframework.poi.excel.entity.ImportParams;
import org.jeecgframework.poi.excel.entity.vo.NormalExcelConstants;

import org.springframework.web.multipart.MultipartFile;
import org.springframework.web.multipart.MultipartHttpServletRequest;

import org.springframework.stereotype.Controller;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.jeecgframework.core.beanvalidator.BeanValidators;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;
import java.net.URI;
import java.util.concurrent.TimeUnit;

import org.springframework.http.MediaType;
import org.springframework.web.util.UriComponentsBuilder;
import org.apache.commons.lang3.StringUtils;
import org.jeecgframework.jwt.util.ResponseMessage;
import org.jeecgframework.jwt.util.Result;
import com.alibaba.fastjson.JSONArray;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;

import static com.xiaoleilu.hutool.date.DateTime.now;

/**   
 * @Title: Controller  
 * @Description: 导入情况
 * @author onlineGenerator
 * @date 2019-02-19 23:07:37
 * @version V1.0   
 *
 */
@Api(value="FxjDhImp",description="导入情况",tags="fxjDhImpController")
@Controller
@RequestMapping("/fxjDhImpController")
public class FxjDhImpController extends BaseController {
	private static final Logger logger = LoggerFactory.getLogger(FxjDhImpController.class);

	@Autowired
	private FxjDhImpServiceI fxjDhImpService;
	@Autowired
	private SystemService systemService;
	@Autowired
	private Validator validator;
	@Autowired
	private UserService userService;


	/**
	 * 导入情况列表 页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "list")
	public ModelAndView list(HttpServletRequest request) {
		return new ModelAndView("com/zhaodui/dhcar/fxjDhImpList");
	}

	/**
	 * easyui AJAX请求数据
	 * 
	 * @param request
	 * @param response
	 * @param dataGrid
	 * @param user
	 */

	@RequestMapping(params = "datagrid")
	public void datagrid(FxjDhImpEntity fxjDhImp,HttpServletRequest request, HttpServletResponse response, DataGrid dataGrid) {
		CriteriaQuery cq = new CriteriaQuery(FxjDhImpEntity.class, dataGrid);
		//查询条件组装器
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, fxjDhImp, request.getParameterMap());
		try{
		//自定义追加查询条件
		
		}catch (Exception e) {
			throw new BusinessException(e.getMessage());
		}
		cq.add();
		this.fxjDhImpService.getDataGridReturn(cq, true);
		TagUtil.datagrid(response, dataGrid);
	}
	
	/**
	 * 删除导入情况
	 * 
	 * @return
	 */
	@RequestMapping(params = "doDel")
	@ResponseBody
	public AjaxJson doDel(FxjDhImpEntity fxjDhImp, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		fxjDhImp = systemService.getEntity(FxjDhImpEntity.class, fxjDhImp.getId());
		message = "导入情况删除成功";
		try{
			fxjDhImpService.delete(fxjDhImp);
			systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
		}catch(Exception e){
			e.printStackTrace();
			message = "导入情况删除失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 批量删除导入情况
	 * 
	 * @return
	 */
	 @RequestMapping(params = "doBatchDel")
	@ResponseBody
	public AjaxJson doBatchDel(String ids,HttpServletRequest request){
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "导入情况删除成功";
		try{
			for(String id:ids.split(",")){
				FxjDhImpEntity fxjDhImp = systemService.getEntity(FxjDhImpEntity.class, 
				Integer.parseInt(id)
				);
				fxjDhImpService.delete(fxjDhImp);
				systemService.addLog(message, Globals.Log_Type_DEL, Globals.Log_Leavel_INFO);
			}
		}catch(Exception e){
			e.printStackTrace();
			message = "导入情况删除失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}


	/**
	 * 添加导入情况
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(params = "doAdd")
	@ResponseBody
	public AjaxJson doAdd(FxjDhImpEntity fxjDhImp, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "导入情况添加成功";
		try{
			fxjDhImpService.save(fxjDhImp);
			systemService.addLog(message, Globals.Log_Type_INSERT, Globals.Log_Leavel_INFO);
		}catch(Exception e){
			e.printStackTrace();
			message = "导入情况添加失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	
	/**
	 * 更新导入情况
	 * 
	 * @param ids
	 * @return
	 */
	@RequestMapping(params = "doUpdate")
	@ResponseBody
	public AjaxJson doUpdate(FxjDhImpEntity fxjDhImp, HttpServletRequest request) {
		String message = null;
		AjaxJson j = new AjaxJson();
		message = "导入情况更新成功";
		FxjDhImpEntity t = fxjDhImpService.get(FxjDhImpEntity.class, fxjDhImp.getId());
		try {
			MyBeanUtils.copyBeanNotNull2Bean(fxjDhImp, t);
			fxjDhImpService.saveOrUpdate(t);
			systemService.addLog(message, Globals.Log_Type_UPDATE, Globals.Log_Leavel_INFO);
		} catch (Exception e) {
			e.printStackTrace();
			message = "导入情况更新失败";
			throw new BusinessException(e.getMessage());
		}
		j.setMsg(message);
		return j;
	}
	

	/**
	 * 导入情况新增页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "goAdd")
	public ModelAndView goAdd(FxjDhImpEntity fxjDhImp, HttpServletRequest req) {
		if (StringUtil.isNotEmpty(fxjDhImp.getId())) {
			fxjDhImp = fxjDhImpService.getEntity(FxjDhImpEntity.class, fxjDhImp.getId());
			req.setAttribute("fxjDhImp", fxjDhImp);
		}
		return new ModelAndView("com/zhaodui/dhcar/fxjDhImp-add");
	}
	/**
	 * 导入情况编辑页面跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "goUpdate")
	public ModelAndView goUpdate(FxjDhImpEntity fxjDhImp, HttpServletRequest req) {
		if (StringUtil.isNotEmpty(fxjDhImp.getId())) {
			fxjDhImp = fxjDhImpService.getEntity(FxjDhImpEntity.class, fxjDhImp.getId());
			req.setAttribute("fxjDhImp", fxjDhImp);
		}
		return new ModelAndView("com/zhaodui/dhcar/fxjDhImp-update");
	}
	
	/**
	 * 导入功能跳转
	 * 
	 * @return
	 */
	@RequestMapping(params = "upload")
	public ModelAndView upload(HttpServletRequest req) {
		req.setAttribute("controller_name","fxjDhImpController");
		return new ModelAndView("common/upload/pub_excel_upload");
	}
	
	/**
	 * 导出excel
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXls")
	public String exportXls(FxjDhImpEntity fxjDhImp,HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {
		CriteriaQuery cq = new CriteriaQuery(FxjDhImpEntity.class, dataGrid);
		org.jeecgframework.core.extend.hqlsearch.HqlGenerateUtil.installHql(cq, fxjDhImp, request.getParameterMap());
		List<FxjDhImpEntity> fxjDhImps = this.fxjDhImpService.getListByCriteriaQuery(cq,false);
		modelMap.put(NormalExcelConstants.FILE_NAME,"导入情况");
		modelMap.put(NormalExcelConstants.CLASS,FxjDhImpEntity.class);
		modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("导入情况列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
			"导出信息"));
		modelMap.put(NormalExcelConstants.DATA_LIST,fxjDhImps);
		return NormalExcelConstants.JEECG_EXCEL_VIEW;
	}
	/**
	 * 导出excel 使模板
	 * 
	 * @param request
	 * @param response
	 */
	@RequestMapping(params = "exportXlsByT")
	public String exportXlsByT(FxjDhImpEntity fxjDhImp,HttpServletRequest request,HttpServletResponse response
			, DataGrid dataGrid,ModelMap modelMap) {
    	modelMap.put(NormalExcelConstants.FILE_NAME,"导入情况");
    	modelMap.put(NormalExcelConstants.CLASS,FxjDhImpEntity.class);
    	modelMap.put(NormalExcelConstants.PARAMS,new ExportParams("导入情况列表", "导出人:"+ResourceUtil.getSessionUser().getRealName(),
    	"导出信息"));
    	modelMap.put(NormalExcelConstants.DATA_LIST,new ArrayList());
    	return NormalExcelConstants.JEECG_EXCEL_VIEW;
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(params = "importExcel", method = RequestMethod.POST)
	@ResponseBody
	public AjaxJson importExcel(HttpServletRequest request, HttpServletResponse response) {
		AjaxJson j = new AjaxJson();
		
		MultipartHttpServletRequest multipartRequest = (MultipartHttpServletRequest) request;
		Map<String, MultipartFile> fileMap = multipartRequest.getFileMap();
		for (Map.Entry<String, MultipartFile> entity : fileMap.entrySet()) {
			MultipartFile file = entity.getValue();// 获取上传文件对象
			ImportParams params = new ImportParams();
			params.setTitleRows(2);
			params.setHeadRows(1);
			params.setNeedSave(true);
			try {
				List<FxjDhImpEntity> listFxjDhImpEntitys = ExcelImportUtil.importExcel(file.getInputStream(),FxjDhImpEntity.class,params);
				for (FxjDhImpEntity fxjDhImp : listFxjDhImpEntitys) {
					fxjDhImpService.save(fxjDhImp);
				}
				j.setMsg("文件导入成功！");
			} catch (Exception e) {
				j.setMsg("文件导入失败！");
				logger.error(ExceptionUtil.getExceptionMessage(e));
			}finally{
				try {
					file.getInputStream().close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return j;
	}


	@RequestMapping(value="/list/{username}", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value="导入情况列表信息",produces="application/json",httpMethod="GET")
	public ResponseMessage<List<FxjDhImpEntity>> list(@PathVariable("username") String username, @RequestParam int pageNumber, @RequestParam int pageSize, HttpServletRequest request) {
		if(pageSize > Globals.MAX_PAGESIZE){
			return Result.error("每页请求不能超过" + Globals.MAX_PAGESIZE + "条");
		}
		CriteriaQuery query = new CriteriaQuery(FxjDhImpEntity.class);
		query.eq("createBy",username);

		if(StringUtil.isNotEmpty(request.getParameter("impFile"))){
			query.like("impFile","%"+request.getParameter("impFile")+"%");
		}
		query.add();

		List<FxjOrderMainEntity> listsize = this.fxjDhImpService.getListByCriteriaQuery(query,false);
		query.setCurPage(pageNumber<=0?1:pageNumber);
		query.setPageSize(pageSize<1?1:pageSize);
		query.add();
		Map<String,Object> map = new HashMap<String,Object>();
		map.put("createDate", "desc");
		query.setOrder(map);

		List<FxjDhImpEntity> listFxjDhImps = this.fxjDhImpService.getListByCriteriaQuery(query,true);
		return Result.success(listFxjDhImps,(long)listsize.size());
	}

	@RequestMapping(value="/uploadexcel", method = RequestMethod.POST)
	@ApiOperation(value="数据上传",notes="数据上传",httpMethod="POST",produces="application/json")
	public @ResponseBody
	LinkedList<FileMeta> upload(    MultipartHttpServletRequest request, HttpServletResponse response) {
		String username = request.getParameter("username");

		LinkedList<FileMeta> files = new LinkedList<FileMeta>();
		String showAndDownUrl = ResourceUtil.getConfigByName("showAndDownUrl");
		String imgserver = ResourceUtil.getConfigByName("img.server");
		FileMeta fileMeta = null;
		//1. build an iterator
		Iterator<String> itr =  request.getFileNames();
		MultipartFile mpf = null;
		String filest = DateUtils.date2Str(DateUtils.yyyymmddhhmmss);
		//2. get each file
		String savaPath= ResourceUtil.getConfigByName("webUploadpath");
		String  filename = "";
		String  filenameweb = "";
		String ctxPath = "";
		while(itr.hasNext()){

			//2.1 get next MultipartFile
			mpf = request.getFile(itr.next());
			System.out.println(mpf.getOriginalFilename() +" uploaded! "+files.size());

			//2.2 if files > 10 remove the first from the list

			filename = filest + File.separator+mpf.getOriginalFilename();
			filenameweb = filest + "/"+mpf.getOriginalFilename();

			FxjOrderAttaEntity fxjOrderAttaEntity = new FxjOrderAttaEntity();
			fxjOrderAttaEntity.setCreateDate(now());
			fxjOrderAttaEntity.setAttaName(filest+File.separator+mpf.getOriginalFilename());
			fxjOrderAttaEntity.setAttaSize(mpf.getSize()/1024+" KB");
			fxjOrderAttaEntity.setBpmStatus("1");
			fxjOrderAttaEntity.setAttaUrl(imgserver+showAndDownUrl+filenameweb);
			//2.3 create new fileMeta
			fileMeta = new FileMeta();
			fileMeta.setFileName(mpf.getOriginalFilename());
			fileMeta.setFileSize(mpf.getSize()/1024+" KB");
			fileMeta.setFileType(mpf.getContentType());
			fileMeta.setFileUrl(fxjOrderAttaEntity.getAttaUrl());
			try {
				fileMeta.setBytes(mpf.getBytes());
				// copy file to local disk (make sure the path "e.g. D:/temp/files" exists)
				  ctxPath=savaPath;

				File file = new File(ctxPath+File.separator+filest);
				if (!file.exists()) {
					file.mkdirs();// 创建文件根目录
				}
				FileCopyUtils.copy(mpf.getBytes(), new FileOutputStream(ctxPath+File.separator+filename));
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			//2.4 add to files
			files.add(fileMeta);



		}
		ImportParams params = new ImportParams();
		params.setTitleRows(0);
		params.setHeadRows(1);
		params.setNeedSave(false);
		try {
			System.out.print("111***"+now());
//			InputStream input = null;
//			input = new File(ctxPath+File.separator+filename);
			List<FxjDhCarInfoEntity> listFxjDhCarInfoEntitys = ExcelImportUtil.importExcel(new File(ctxPath+File.separator+filename),FxjDhCarInfoEntity.class,params);
			System.out.print("22222***"+now());

			FxjDhImpEntity fxjDhImpEntity = new FxjDhImpEntity();
			fxjDhImpEntity.setCreateDate(now());
			fxjDhImpEntity.setCreateBy(username);
			fxjDhImpEntity.setImpFile(filename);
			fxjDhImpEntity.setImpCount(Integer.toString(listFxjDhCarInfoEntitys.size()));
			String impid = systemService.save(fxjDhImpEntity).toString();
			for (FxjDhCarInfoEntity fxjDhCarInfo : listFxjDhCarInfoEntitys) {
				fxjDhCarInfo.setCreateBy(username);
				fxjDhCarInfo.setCreateDate(now());
				fxjDhCarInfo.setCarGroup(impid);
                String engineo = fxjDhCarInfo.getCarFreno();
                String carvin = fxjDhCarInfo.getCarVin();
                if(StringUtil.isNotEmpty(carvin)){
                    String[] args=carvin.split("\\.");
                    fxjDhCarInfo.setCarVin(args[0]);
                }
                if(StringUtil.isNotEmpty(engineo)) {
                    String[] args1 = engineo.split("\\.");
                    fxjDhCarInfo.setCarFreno(args1[0]);
                }
				systemService.save(fxjDhCarInfo);
			}
		}catch (Exception e){

		}
		return files;
	}



	@RequestMapping(value = "/{id}", method = RequestMethod.GET)
	@ResponseBody
	@ApiOperation(value="根据ID获取导入情况信息",notes="根据ID获取导入情况信息",httpMethod="GET",produces="application/json")
	public ResponseMessage<?> get(@ApiParam(required=true,name="id",value="ID")@PathVariable("id") String id) {
		FxjDhImpEntity task = fxjDhImpService.get(FxjDhImpEntity.class, id);
		if (task == null) {
			return Result.error("根据ID获取导入情况信息为空");
		}
		return Result.success(task);
	}

    @RequestMapping(value = "/querywz/{id}", method = RequestMethod.GET)
    @ResponseBody
    @ApiOperation(value="根据ID获取导入情况信息",notes="根据ID获取导入情况信息",httpMethod="GET",produces="application/json")
    public ResponseMessage<?> getquery(@ApiParam(required=true,name="id",value="id")@PathVariable("id") String id,HttpServletRequest request) {


		StringRedisTemplate redisTemplate =ApplicationContextUtil.getContext().getBean(StringRedisTemplate.class);
		if(redisTemplate.hasKey(id)){
			return Result.error("此批正在查询，请勿重复查询");
		}else{
			redisTemplate.boundValueOps(id).set(id, 3600, TimeUnit.SECONDS);
		}


		if (userService.isInWhiteList(IpUtil.getIpAddr(request))){
			return Result.error(IpUtil.getIpAddr(request)+"没有在白名单，请联系管理员加入");

		}

		com.zhaodui.jdwx.jdwxController jdwx = new jdwxController();
        int runcount = 0;
	    List<FxjDhCarInfoEntity> dhcar = systemService.findByProperty(FxjDhCarInfoEntity.class,"carGroup",id);
        //查询开始
        for(FxjDhCarInfoEntity  t: dhcar){
            String result = "";
            String username = t.getCreateBy();
           String  frameno=t.getCarVin();
           if (StringUtil.isNotEmpty(frameno)){
               if (StringUtil.getStringLen(frameno)>6){
                   frameno = frameno.substring(frameno.length()-6, frameno.length());
               }
           }
           String  engineno=t.getCarFreno();
            if (StringUtil.isNotEmpty(engineno)){
                if (StringUtil.getStringLen(engineno)>6){
                    engineno = engineno.substring(engineno.length()-6, engineno.length());
                }
            }
            try {
                result = jdwx.do360wz(username,t.getCarNo(),frameno,engineno,request);
                try{
                    FxjDhfkLogEntity fxjDhfkLogEntity = new FxjDhfkLogEntity();
                    fxjDhfkLogEntity.setCreateBy(username);
                    fxjDhfkLogEntity.setFkName("do360wz");
                    fxjDhfkLogEntity.setFkResult(result);
                    systemService.save(fxjDhfkLogEntity);
                }catch (Exception e){

                }
            } catch (Exception e) {
                e.printStackTrace();
            }
            try{
                fxj360wz fxj360Wz = JSONHelper.fromJsonToObject(result,fxj360wz.class);
                t.setCarStatus("查询成功");
                try{
                    t.setCarEzjine(Integer.toString(fxj360Wz.getResult().getWzfkhj()));

                }catch (Exception e){

                }
                try{
                    t.setCarWzscore(Integer.toString(fxj360Wz.getResult().getWzjfhj()));

                }catch (Exception e){

                }
                try{
                    t.setCarRunFrq(Integer.toString(fxj360Wz.getResult().getWzts()));

                }catch (Exception e){

                }
                try{
                    for(com.zhaodui.restapi.entity.fxj360wz.ResultBean.DataBean dt:fxj360Wz.getResult().getData()){
                        FxjDhCarWzdetailEntity fxjDhCarWzdetailEntity = new FxjDhCarWzdetailEntity();
                        fxjDhCarWzdetailEntity.setCarNo(fxj360Wz.getResult().getCph());
						fxjDhCarWzdetailEntity.setFrameno(t.getCarVin());
						fxjDhCarWzdetailEntity.setEngineno(t.getCarFreno());
                        fxjDhCarWzdetailEntity.setCharge(Boolean.toString(fxj360Wz.isCharge()));
                        fxjDhCarWzdetailEntity.setWzid(dt.getWfdm());
                        fxjDhCarWzdetailEntity.setTime(dt.getWzsj());
                        fxjDhCarWzdetailEntity.setAddress(dt.getWzdd());
                        fxjDhCarWzdetailEntity.setContent(dt.getWzxw());
                        fxjDhCarWzdetailEntity.setPrice(Integer.toString(dt.getWzfk()));
                        fxjDhCarWzdetailEntity.setScore(Integer.toString(dt.getWzjf()));
						fxjDhCarWzdetailEntity.setCsmc(dt.getCsmc());
						fxjDhCarWzdetailEntity.setCsdm(dt.getCsdm());
						fxjDhCarWzdetailEntity.setWzid(dt.getWfdm());
                        fxjDhCarWzdetailEntity.setQueryOrderno(t.getCarGroup());
                        try{
                            fxjDhCarWzdetailEntity.setBy1(result);
							systemService.save(fxjDhCarWzdetailEntity);
						}catch (Exception e){
                        }
                    }
                }catch (Exception e){
                }
            }catch (Exception e){
                try{
                    jdwxerrres jdwxerrres = JSONHelper.fromJsonToObject(result,jdwxerrres.class);
                    t.setCarStatus(result);
                }catch (Exception e1){
                }
            }
            systemService.updateEntitie(t);
            //查询结束
           //更新查询条数
            runcount =runcount + 1;
            FxjDhImpEntity fxjDhImpEntity = fxjDhImpService.get(FxjDhImpEntity.class, Integer.parseInt(id));
            if (fxjDhImpEntity!=null){
                fxjDhImpEntity.setQueryCount(Integer.toString(runcount));
                fxjDhImpService.updateEntitie(fxjDhImpEntity);
            }
            //更新查询条数
        }
		redisTemplate.delete(id);

		return Result.success("执行成功");
    }



	@RequestMapping(method = RequestMethod.POST, consumes = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@ApiOperation(value="创建导入情况")
	public ResponseMessage<?> create(@ApiParam(name="导入情况对象")@RequestBody FxjDhImpEntity fxjDhImp, UriComponentsBuilder uriBuilder) {
		//调用JSR303 Bean Validator进行校验，如果出错返回含400错误码及json格式的错误信息.
		Set<ConstraintViolation<FxjDhImpEntity>> failures = validator.validate(fxjDhImp);
		if (!failures.isEmpty()) {
			return Result.error(JSONArray.toJSONString(BeanValidators.extractPropertyAndMessage(failures)));
		}

		//保存
		try{
			fxjDhImpService.save(fxjDhImp);
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error("导入情况信息保存失败");
		}
		return Result.success(fxjDhImp);
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.PUT, consumes = MediaType.APPLICATION_JSON_VALUE)
	@ResponseBody
	@ApiOperation(value="更新导入情况",notes="更新导入情况")
	public ResponseMessage<?> update(@ApiParam(name="导入情况对象")@RequestBody FxjDhImpEntity fxjDhImp) {
		//调用JSR303 Bean Validator进行校验，如果出错返回含400错误码及json格式的错误信息.
		Set<ConstraintViolation<FxjDhImpEntity>> failures = validator.validate(fxjDhImp);
		if (!failures.isEmpty()) {
			return Result.error(JSONArray.toJSONString(BeanValidators.extractPropertyAndMessage(failures)));
		}

		//保存
		try{
			fxjDhImpService.saveOrUpdate(fxjDhImp);
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error("更新导入情况信息失败");
		}

		//按Restful约定，返回204状态码, 无内容. 也可以返回200状态码.
		return Result.success("更新导入情况信息成功");
	}

	@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
	@ResponseStatus(HttpStatus.NO_CONTENT)
	@ApiOperation(value="删除导入情况")
	public ResponseMessage<?> delete(@ApiParam(name="id",value="ID",required=true)@PathVariable("id") String id) {
		logger.info("delete[{}]" , id);
		// 验证
		if (StringUtils.isEmpty(id)) {
			return Result.error("ID不能为空");
		}
		try {
			fxjDhImpService.deleteEntityById(FxjDhImpEntity.class, id);
		} catch (Exception e) {
			e.printStackTrace();
			return Result.error("导入情况删除失败");
		}

		return Result.success();
	}
}
